//
//  ViewController.swift
//  FirstSwiftTest
//
//  Created by Tssup on 16/2/26.
//  Copyright © 2016年 com.tssup. All rights reserved.
//

import UIKit

class ViewController: UIViewController
{

    var nickName:String = "jim";
    let name = "jim";//常量
    var age:Int = 20;
    var sex:Int = 1;
    var marriage:Bool = false;
    var dic = ["1":"一","2":"二"];
    //1.定义数组
    var arr:[Int] = [1,3,5,7,9];
    var arr1 = [Int](count: 3, repeatedValue: 1);//等价于 [1, 1, 1]
    var strarr:[String] = ["理想","swift"];
    typealias MyStr = String;//类型别名（type aliases）就是给现有类型定义另一个名字
    var httpError = (code:404, msg:"Not Found");//元组（tuples）把多个值组合成一个复合值。元组内的值可以是任意类型，并不要求是相同类型    var strChange:String
    var selectType:String?;//可选类型
    var selectType2:String!="345";//隐式解析可选类型
    var strChange:String{
        get
        {
            return "==strChange ==get="
        }
        set
        {
            print("==strChange==set=");
        }
    }
    var fuc:()->()={
            print("===函数=fuc==")
    }
    var fuc5:(String,String)->(NSString)={a,b in
        print("==函数和元组==",a,b);
        return a+b;
    }
    override func viewDidLoad()
    {
        super.viewDidLoad()
        for x in 1...10
        {
            print("x==:\(x)");
        }
        for x in 1..<10
        {
            print("半开区间x2==:",x);
        }
        let integerToDescribe = 5
        var description = "The number \(integerToDescribe) is"
        switch integerToDescribe {
        case 2, 3, 5, 7, 11, 13, 17, 19:
            description += " a prime number, and also"
            fallthrough//贯穿（Fallthrough）
        default:
            description += " an integer."
        }
        print(description)
        // 输出 "The number 5 is a prime number, and also an integer."
        var arr0 = arr1+arr;
        print("数组联合===",arr0);
        arr0[0...3]=[0,0];//从0到3共4个元素替换为0,0
        print("数组联合=2==",arr0);
        let str = String(dic["1"]);
        print("dic===",str=="一",dic.values);        let twoThousand: UInt16 = 2_000
        let one: UInt8 = 1
        let twoThousandAndOne = twoThousand + UInt16(one)//常量twoThousand是UInt16类型，然而常量one是
        //UInt8类型。它们不能直接相加
        print("不同数值类型 相加===",twoThousandAndOne);
        var myStrTest:MyStr = "abc";//类型别名的使用
        myStrTest = "123";
        print("类型别名的使用===",myStrTest);
        print("元组使用==:",httpError.code,httpError.0,httpError.1);
        httpError=(40,"msg");
        print("元组使用=2=:",httpError.code,httpError.0,httpError.1);
        let (justTheStatusCode, _) = httpError
        print("元组使用=3=: \(justTheStatusCode)");
        selectType = "123";
        print("可选式selectType===",selectType);
        if let intType2 = Int(selectType!)
        {
            print("selectType=22==",intType2);
        }
        let intType = selectType2;
        print("隐式解析可选类型===",intType);
        //
        fuc();
        fuc5("aa"," 10");
        self.printFuncFunc(10,b: 20);
        let fuc56:(Int,Int)->(Int)=func5566;
        print(fuc56(5,6));
        nickName = "jack";
        NSLog("name== nickName==:%@", name+"-"+nickName+"="+strChange);
        strChange = "change";
      
        
        //self.fuc22;
        let strA = fuc22("aaaa", bb:"bbb");
        print(strA.a,strA.b,strA.c);
        fuc33(String: "yeah");
        fuc44(name: "abc",arrStr: "a","b","c");
    }
    func printFuncFunc(a:Int,b:Int)->()
    {
        func countFunc(a:Int,b:Int)->(Int)
        {
            return a+b;
        }
        func trace()
        {
            let count:Int=countFunc(a,b: b);
            print("printFuncFunc=====",count);
        }
        trace();
    }
    func func5566(a: Int, b: Int)->(Int)
    {
        return a + b
    }
    func fuc22(aa:String,bb:String)->(a: String, b: Int, c: Int)
    {
        return (aa+"-"+"fuc22",10,5);
    }
    func fuc33(String aa:String)
    {
        print("==fuc33====aa===="+aa);
    }
    func fuc44(name str:String,arrStr: String...)
    {
        print("==fuc44===",str,arrStr);
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

